package cn.iocoder.yudao.module.pay.job.ftp;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.ftp.Ftp;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Service
@Slf4j
public class FtpServiceImpl implements FtpService {
    @Resource
    private FtpConfig ftpConfig;


    @Override
    public List<File> getFiles(String path) throws IOException {
        Ftp ftp = ftpConfig.getFtp();
        List<String> list = ftp.ls(path);
        InputStream inputStream = null;
        for (String str : list) {
            str = path + File.separator + str;
            log.info("文件路径：{}", str);
            // 打开文件输入流
            inputStream = ftp.getClient().retrieveFileStream(str);

        }
        return null;
    }

    /***
     * 解析表格
     * @param inputStream
     */
    private static void getExcelCont(InputStream inputStream) {
        ExcelReader reader = ExcelUtil.getReader(inputStream);
        List<List<Object>> list = reader.read(1);
        if (CollUtil.isEmpty(list)) {
            return;
        }
    }

    @Override
    public Boolean delFile(String fileName) {
        return ftpConfig.getFtp().delFile(fileName);
    }
}
